﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Maticsoft.Common.DEncrypt;
using Maticsoft.Common;

namespace Maticsoft.Web.wap
{
    public partial class Login : BasePage
    {
        string retUrl = "default.aspx";
        protected void Page_Load( object sender, EventArgs e )
        {
            if (!string.IsNullOrEmpty(Request.QueryString["retUrl"]))
            {
                retUrl = Request.QueryString["retUrl"];
            }
        }

        protected void btnLogin_Click( object sender, EventArgs e )
        {
            string userName = txtMobile.Value.Trim();
            string pwd = DEncrypt.Encrypt(txtPassword.Value.Trim());
            BLL.Members meBLL = new BLL.Members();
            Model.Members meModel = meBLL.GetModel(userName, pwd);
            if (meModel == null)
            {
                MessageBox.Show(this.Page, "用户名或者密码错误");
                return;
            }

            if (meModel.IsActive == 0)
            {
                MessageBox.Show(this.Page, "用户名或者密码错误");
                return;
            }

            if (meModel.Status == 0)
            {
                MessageBox.Show(this.Page, "账号未激活");
                return;
            }

            Session["UserId"] = meModel.UserId;
            Session["ManagerName"] = meModel.UserName;
            Session["GroupId"] = meModel.GroupId;
            Session["LevelId"] = meModel.LevelId;

            Response.Redirect(retUrl);
        }
    }
}